<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page import="dao.UserDAO" %>
<%@ page import="model.UserModel" %>
<%@ page import="common.Constant" %>
<%@ page import="java.util.ArrayList"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=${encoding}">
        <title>ChangPassword Page</title>

<script type="text/javascript" language="JavaScript">
        function submitForm(){
            document.forms["changePass"].submit();
	}

        function checkPassword(){
            var opass = document.forms["changePass"].txtOPass.value.trim();
            var sopass = document.forms["changePass"].txtSOPass.value.trim();
            var pass1 = document.forms["changePass"].txtNPass.value.trim();
            var pass2 = document.forms["changePass"].txtCNPass.value.trim();

            if(opass != sopass){
                alert("Old password invalid!");
                document.forms["changePass"].txtOPass.value = "";
                return;
            }

            if(pass1.length.trim() < 6){
                alert("New password must more than 6 character!");
                document.forms["changePass"].txtNPass.value = "";
                document.forms["changePass"].txtCNPass.value = "";
                return;
            }

            if(pass1 != pass2){
                alert("Confirm password invalid!");
                document.forms["changePass"].txtNPass.value = "";
                document.forms["changePass"].txtCNPass.value = "";
                return;
            }
            submitForm();
        }
</script>

    </head>
    <body>
        <div id="main_container">
		<!-- S HEAD CONTENT -->
            <jsp:include page="block/header.jsp" />
            <!-- E HEAD CONTENT -->

            <!-- S Top Menu -->
            <jsp:include page="block/top_menu.jsp" />
            <!-- E Top Menu -->

            <!-- S Navigation -->
            <jsp:include page="block/navigation.jsp" />
            <!-- E Navigation -->

            <!-- S Left Menu -->
            <jsp:include page="block/left_menu.jsp" />
            <!-- E Left Menu -->

		<!-- S Body Content -->
                <div class="center_content">
                <form action="UserController?changePass=yes" method="post" id="changePass" name="changePass">
                    <c:if test="${not empty param.msg and param.msg eq 'success'}">
                            <b class="msg"> Change password success </b>
                    </c:if>
                    <table align="center" cellpadding="3" cellspacing="3" border="0">
                        <tr>
                            <td colspan="2" align="center"><h2>ChangePassword</h2></td>
                        </tr>
                        <tr>
                            <td>OldPass : </td>
                            <td> <input type="password" id="txtOPass" name="txtOPass" />
                                <input type="hidden" id="txtSOPass" name="txtSOPass" value="${sessionScope.password}" />
                                <input type="hidden" id="txtUserID" name="txtUserID" value="${sessionScope.userID}" />
                            </td>
                        </tr>
                        <tr>
                            <td>NewPass : </td>
                            <td> <input type="password" id="txtNPass" name="txtNPass" /> </td>
                        </tr>
                        <tr>
                            <td>Confirm NewPass : </td>
                            <td> <input type="password" id="txtCNPass" name="txtCNPass" /> </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center"> <input type="button" value="Submit" onclick="checkPassword()" /> </td>
                        </tr>
                    </table>
                </form>
                </div>
		<!-- E Body Content -->

                <!-- S Footer -->
			<jsp:include page="block/footer.jsp" />
		<!-- E Footer -->
	</div>
    </body>
</html>
